package com.example.myapplication.tack_10;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_10.data.ArrangeData;
import com.example.myapplication.tack_10.data.XQData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

public class XQActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView image;
    private TextView text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_10_activity_x_q);
        init();
        exit_();
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        getXQ(id);
    }

    private void getXQ(String id) {
        String url = "prod-api/api/gov-service-hotline/appeal/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, XQData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                XQData xQData = (XQData)obj;
                if(xQData.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            xQAdapter(xQData);
                        }


                    });
                }

            }

            @Override
            public void onFailure(String msg) {
            }
        });
    }

    private void xQAdapter(XQData xQData) {
        Glide.with(XQActivity.this).load(OkHttpTool.URL + xQData.getData().getImgUrl()).into(image);
        text.setTextSize(18);
        if( "0".equals(xQData.getData().getState())){
            text.setText(xQData.getData().getTitle()+"\n\n\n"+ xQData.getData().getContent()+"\n\n\n"+
                    "未处理"+"\n\n\n"+ xQData.getData().getCreateTime()
            );
        }else   if( "1".equals(xQData.getData().getState())){
            text.setText(xQData.getData().getTitle()+"\n"+ xQData.getData().getContent()+"\n\n\n"+
                    "已处理"+"\n\n\n"+ xQData.getData().getCreateTime()
            );
        }


    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                XQActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        text = findViewById(R.id.text);
        image = findViewById(R.id.imags);
    }
}